{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 多重索引，又可以称为“分层索引”\n",
    "多重索引在Pandas中也是一种对象，即MultiIndex对象，其与标准的Index对象非常相似。\n",
    "可以将多重索引对象看成是一个由元组（tuple）元素组成的数组，其中，每一个元组对象都是唯一的。\n",
    "MultiIndex既可以由嵌套数组创建（使用MultiIndex.from_arrays)，也可以由元组组成的数组创建（使用MultiIndex.from_tuples)\n",
    "或者指定每个维度的索引值，自动循环生成索引（使用MultiIndex.from_product)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MultiIndex(levels=[['000001', '600000', '688001'], [2016, 2017]],\n",
       "           labels=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],\n",
       "           names=['code', 'year'])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "numbers = ['000001', '600000', '688001']\n",
    "colors = [2016, 2017]\n",
    "mindex = pd.MultiIndex.from_product([numbers, colors], names = ['code', 'year'])\n",
    "mindex"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
